package com.baiyapeng.code;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

/**
 * 程序入口
 */
public class App implements WebApplicationInitializer {

    /*public static void main(String[] args) {
        System.out.println("Hello World!");
    }*/

    /**
     * 扫描spring容器并注册web服务
     */
    @Override
    public void onStartup(ServletContext servletContext) {
        XmlWebApplicationContext applicationContext = new XmlWebApplicationContext();
        applicationContext.setConfigLocation("classpath:application.xml");

        ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcherServlet", new DispatcherServlet(applicationContext));
        registration.addMapping("/");
        registration.setLoadOnStartup(1);
    }
}